package com.have.blog.commons.fallback;

import com.have.blog.base.holder.RequestHolder;
import com.have.blog.commons.feign.PictureFeignClient;
import com.have.blog.commons.vo.FileVo;
import com.have.blog.utils.ResultUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@Component
@Slf4j
public class PictureFeignFallback implements PictureFeignClient {
    @Override
    public String getPicture(String fileIds, String code) {
        logError("获取图片失败");
        return ResultUtils.errorWithMessage("获取图片服务降级返回");
    }

    @Override
    public String uploadPicsByUrl(FileVo fileVo) {
        logError("更新图片失败");
        return ResultUtils.errorWithMessage("更新图片服务降级返回");
    }

    @Override
    public String initStorageSize(String adminUid, Long maxStorageSize) {
        logError("初始化网盘容量失败");
        return ResultUtils.errorWithMessage("图片服务出现异常，初始化网盘容量失败");
    }

    @Override
    public String editStorageSize(String adminUid, Long maxStorageSize) {
        logError("更新网盘容量失败");
        return ResultUtils.errorWithMessage("图片服务出现异常，更新网盘容量失败，服务降级返回");
    }

    @Override
    public String getStorageByAdminUid(List<String> adminUidList) {
        logError("获取网盘容量失败");
        return ResultUtils.errorWithMessage("图片服务出现异常，更新网盘容量失败，服务降级返回");
    }

    private void logError(String info) {
        HttpServletRequest request = RequestHolder.getRequest();
        StringBuffer requestURL = request.getRequestURL();
        log.error("图片服务出现异常，" + info + "，服务器降级返回，请求路径:{}", requestURL);
    }
}
